﻿define([
'Wjs/ui/elements/View',
'Wjs/ui/widgets/fields/TextField',
'Wjs/ui/widgets/tools/TimeSelector'
],
function (View) {
    'use strict';

    var type = 'timeField',
    typeManager = Wjs.typeManager,
    TimeField = typeManager.getType(type);

    if (TimeField) { // It has been already loaded
        return TimeField;
    }

    TimeField = Wjs.typeBuilder.define({
        base: View,
        construct: function (conf, parent) {
            var me = this;

            TimeField.base.constructor.call(me, conf, parent);

            me.addClass('wjs-time-field');

            // The contained text field
            me.field = me.createChild({
                name: conf.name,
                value: conf.value,
            }, 'TextField');

            //me.field.addClass('w-input-date');

            // The tool that opens a time selector
            me.tool = me.createChild({}, 'timeSelector');
            me.tool.addClass('wjs-tool');
        },

        type: type,

        setValue: function (val, options) {
            this.field.setValue(val, options);
        },

        getValue: function () {
            return this.field.getValue();
        },

        enable: function () {
            this.field.enable();
        },

        disable: function () {
            this.field.disable();
        }

    });

    typeManager.registerType(TimeField);

    return TimeField;
});